package com.hotelManagerSystem.mapper;

import com.hotelManagerSystem.model.Permission;
import com.hotelManagerSystem.model.RolePermission;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  角色--权限 Mapper 接口
 * </p>
 *
 * @author longyajr
 * @since 2021-12-22
 */
public interface RolePermissionMapper extends BaseMapper<RolePermission> {

    @Delete("DELETE FROM role_permission WHERE role_id = #{roleId}")
    boolean deleteRolePermissionByRoleId (int roleId);

    /**
     * @author treasy
     * @description 根据用户id获取所有权限信息
     * @param staffId
     * @return
     */
    @Select("SELECT\n" +
            "permission.permission_id,\n" +
            "permission.permission_name,\n" +
            "permission.permission_code\n" +
            "FROM\n" +
            "staff\n" +
            "INNER JOIN staff_role ON staff.staff_id = staff_role.staff_id\n" +
            "INNER JOIN role ON staff_role.role_id = role.role_id\n" +
            "INNER JOIN role_permission ON role.role_id = role_permission.role_id\n" +
            "INNER JOIN permission ON role_permission.permission_id = permission.permission_id\n" +
            "WHERE\n" +
            "staff.staff_id")
    List<Permission> queryAllPermissionByStaffId(int staffId);

    @Delete("delete from role_permission WHERE permission_id=#{permissionId}")
    boolean deleteByPermissionId(int permissionId);
}
